package com.gg.controller;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public class BuildCompleteEventFinder {
	
	private Zedis zedis;

	public BuildCompleteEventFinder(Zedis zedis) {
		this.zedis = zedis;
		
	}
	
	public List<BuildEvent> find() {
		List<BuildEvent> eventList = new ArrayList<BuildEvent>();

		Set<String> keySet = zedis.zrange("build:woodcutter", 0, 10);

		Iterator<String> iterator = keySet.iterator();
		while (iterator.hasNext()) {
			// userId:time
			String key = (String) iterator.next();
			BuildEvent buildEvent = new BuildEvent(key);
			if (buildEvent.hasCompleted()) {
				eventList.add(buildEvent);
				zedis.zrem("build:woodcutter", key);
			}
		}

		return eventList;
	}

}
